local difa = fk.CreateSkill {

  name = "joy__difa",

  tags = {  },

}



difa:addEffect("active", {
  name = "joy__difa",
  anim_type = "drawcard",
  prompt = "#joy__difa",
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(difa.name, Player.HistoryPhase) == 0
  end,
  card_num = 1,
  card_filter = function(self, player, to_select, selected)
    return #selected < 1 and Fk:getCardById(to_select).color == Card.Red
  end,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = effect.from
    room:moveCards({
      ids = effect.cards,
      from = player.id,
      toArea = Card.DiscardPile,
      skillName = difa.name,
      moveReason = fk.ReasonPutIntoDiscardPile,
      proposer = player.id
    })
    if player.dead then return end
    player:drawCards(1,difa.name)
    local allCardMapper = {}
    local allCardNames = {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if  card.type == Card.TypeTrick and room:getCardArea(id) == Card.DrawPile then
        if allCardMapper[card.name] == nil then
          allCardMapper[card.name] = {}
          table.insert(allCardNames, card.name)
        end
        table.insert(allCardMapper[card.name], id)
      end
    end
    if #allCardNames == 0 then return end
    local cardName = room:askForChoice(player, allCardNames, difa.name)
    room:moveCardTo(table.random(allCardMapper[cardName]), Card.PlayerHand, player, fk.ReasonPrey, difa.name)
  end,
})

return difa